package com.ht.right.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.ht.right.entity.WorkFlow;
import com.ht.right.service.WorkFlowService;
import com.ht.right.util.CommonUtil;
import com.opensymphony.xwork2.ActionSupport;

public class WorkFlowAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private WorkFlowService workFlowService;
	private WorkFlow workFlow;
	
	public String addWorkFlow(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String menuId = request.getParameter("menuId");
		workFlowService.addWorkFlow(workFlow,menuId);
		return null;
	}
	
	public String updateWorkFlow(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String menuId = request.getParameter("menuId");
		workFlowService.updateWorkFlow(workFlow,menuId);
		return null;
	}
	
	public String getWorkFlowByMenuId(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String menuId = request.getParameter("menuId");
		workFlow = workFlowService.getWorkFlowByMenuId(menuId);
		return "success";
	}
	
	public String getWorkFlowXml(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String workFlowId = request.getParameter("wfId");
		workFlow =  workFlowService.getWorkFlowById(workFlowId);
		CommonUtil.toString(ServletActionContext.getResponse(), "<WorkFlow>"+workFlow.getWfProcessXml()+"<Log/>"+workFlow.getWfGraphXml()+"</WorkFlow>");
		return null;
	}
	
	public String getWorkFlowById(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String workFlowId = request.getParameter("wfId");
		workFlow =  workFlowService.getWorkFlowById(workFlowId);
		return "success";
	}
	
	public String findAllWF(){
		CommonUtil.toJsonStr(ServletActionContext.getResponse(), workFlowService.findWFTree());
		return null;
	}
	
	public WorkFlowService getWorkFlowService() {
		return workFlowService;
	}
	public void setWorkFlowService(WorkFlowService workFlowService) {
		this.workFlowService = workFlowService;
	}


	public WorkFlow getWorkFlow() {
		return workFlow;
	}


	public void setWorkFlow(WorkFlow workFlow) {
		this.workFlow = workFlow;
	}
}
